Skip to contentSkip to conversation

Change in openvpn[master]: Enable per-socket bind_dev via --local

Openvpn-devel its_Giaan (Code Review) 1 participant 10 messages Apr 9 – Apr 15 1 message not in the archive

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): gerrit.1775741612000.I6319c951327a9b994ffae0ba35270b0887455203@...2715...

#1 lore raw

Attention is currently required from: plaisthos.

Hello plaisthos,

I'd like you to do a code review.
Please visit

    http://gerrit.openvpn.net/c/openvpn/+/1625?usp=email

to review the following change.

Change subject: Enable per-socket bind_dev via --local
......................................................................

Enable per-socket bind_dev via --local

A bind device can now be specified within a
--local statement allowing to bind
different sockets to different devices.

Change-Id I6319c951327a9b994ffae0ba35270b0887455203

---
M doc/man-sections/link-options.rst
M src/openvpn/options.c
M src/openvpn/options.h
M src/openvpn/socket.c

4 files changed, 19 insertions(+), 4 deletions(-)

git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/25/1625/1

doc/man-sections/link-options.rst +1 -1
index edda1ca..4b3200a 100644
@@ -111,7 +111,7 @@
   Valid syntax:
   ::
 
-     local host|* [port] [protocol]
+     local host|* [port] [protocol] [bind device]
 
   Local host name or IP address and port for bind. If specified, OpenVPN will bind
   to this address. If unspecified, OpenVPN will bind to all interfaces.
src/openvpn/options.c +14 -2
index b8d0f5a..6958953 100644
@@ -3830,6 +3830,7 @@
         ASSERT(e);
         e->port = o->ce.local_port;
         e->proto = o->ce.proto;
+        e->bind_dev = o->bind_dev;
     }
 
     /* use the same listen list for every outgoing connection */
@@ -5972,7 +5973,7 @@
         VERIFY_PERMISSION(OPT_P_UP);
         options->ifconfig_nowarn = true;
     }
-    else if (streq(p[0], "local") && p[1] && !p[4])
+    else if (streq(p[0], "local") && p[1] && !p[5])
     {
         struct local_entry *e;
 
@@ -5998,6 +5999,17 @@
         {
             e->proto = ascii2proto(p[3]);
         }
+#if defined(TARGET_LINUX)
+        if (p[4])
+        {
+            e->bind_dev = p[4];
+        }
+#else
+        if (p[4])
+        {
+            msg(M_WARN | M_ERRNO, "Note: bind_dev is ignored on non-Linux systems");
+        }
+#endif
     }
     else if (streq(p[0], "remote-random") && !p[1])
     {
@@ -6526,7 +6538,7 @@
             }
         }
     }
-#ifdef TARGET_LINUX
+#if defined(TARGET_LINUX)
     else if (streq(p[0], "bind-dev") && p[1])
     {
         VERIFY_PERMISSION(OPT_P_SOCKFLAGS);
src/openvpn/options.h +1 -0
index 422820c..0c4d11c 100644
@@ -101,6 +101,7 @@
     const char *local;
     const char *port;
     int proto;
+    const char *bind_dev;
 };
 
 struct connection_entry
src/openvpn/socket.c +3 -1
index 624ce4f..9c69ca4 100644
@@ -1349,6 +1349,7 @@
     const char *host = o->ce.local_list->array[sock_index]->local;
     const char *port = o->ce.local_list->array[sock_index]->port;
     int proto = o->ce.local_list->array[sock_index]->proto;
+    const char *bind_dev = o->ce.local_list->array[sock_index]->bind_dev;
     const char *remote_host = o->ce.remote;
     const char *remote_port = o->ce.remote_port;
 
@@ -1409,7 +1410,8 @@
 #endif
 
     sock->mark = o->mark;
-    sock->bind_dev = o->bind_dev;
+    /* bind_dev from local_list will trump on the global option. */
+    sock->bind_dev = bind_dev ? bind_dev : o->bind_dev;
     sock->info.proto = proto;
     sock->info.af = o->ce.af;
     sock->info.remote_float = o->ce.remote_float;

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1625?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings?usp=email

Gerrit-MessageType: newchange
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I6319c951327a9b994ffae0ba35270b0887455203
Gerrit-Change-Number: 1625
Gerrit-PatchSet: 1
Gerrit-Owner: its_Giaan <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>

#2 lore raw
In reply to a message not in the archive

Attention is currently required from: its_Giaan, plaisthos.

flichtenheld has posted comments on this change by its_Giaan. ( http://gerrit.openvpn.net/c/openvpn/+/1625?usp=email )

Change subject: Enable per-socket bind_dev via --local
......................................................................

Patch Set 1: Code-Review-1

(4 comments)

File doc/man-sections/link-options.rst:

http://gerrit.openvpn.net/c/openvpn/+/1625/comment/15733805_d4bc2521?usp=email :
PS1, Line 114: local host|* [port] [protocol] [bind device]
Should also add a reference to --bind-dev somewhere in the documentation below. I realize we do not have corresponding references for port and protocol either, but maybe we can also fix that?

File src/openvpn/options.c:

http://gerrit.openvpn.net/c/openvpn/+/1625/comment/d6b4199e_963ab8ae?usp=email :
PS1, Line 6010: msg(M_WARN | M_ERRNO, "Note: bind_dev is ignored on non-Linux systems");
No syscalls involved here, so M_ERRNO makes no sense

http://gerrit.openvpn.net/c/openvpn/+/1625/comment/b13fa4de_a8359f50?usp=email :
PS1, Line 6541: #if defined(TARGET_LINUX)
Why this random change?

File src/openvpn/socket.c:

http://gerrit.openvpn.net/c/openvpn/+/1625/comment/90dda228_fbf9b24f?usp=email :
PS1, Line 1413: /* bind_dev from local_list will trump on the global option. */
Remove "on", remove the trailing full stop

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1625?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings?usp=email

Gerrit-MessageType: comment
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I6319c951327a9b994ffae0ba35270b0887455203
Gerrit-Change-Number: 1625
Gerrit-PatchSet: 1
Gerrit-Owner: its_Giaan <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: its_Giaan <[email protected]...>
Gerrit-Comment-Date: Mon, 13 Apr 2026 11:20:44 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: Yes

#3 lore raw
In reply to a message not in the archive

Attention is currently required from: flichtenheld, its_Giaan, plaisthos.

Hello flichtenheld, plaisthos,

I'd like you to reexamine a change. Please visit

    http://gerrit.openvpn.net/c/openvpn/+/1625?usp=email

to look at the new patch set (#2).

The following approvals got outdated and were removed:
Code-Review-1 by flichtenheld

Change subject: Enable per-socket bind_dev via --local
......................................................................

Enable per-socket bind_dev via --local

A bind device can now be specified within a
--local statement allowing to bind
different sockets to different devices.

Change-Id I6319c951327a9b994ffae0ba35270b0887455203

---
M doc/man-sections/link-options.rst
M doc/man-sections/vpn-network-options.rst
M src/openvpn/options.c
M src/openvpn/options.h
M src/openvpn/socket.c

5 files changed, 21 insertions(+), 4 deletions(-)

git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/25/1625/2

doc/man-sections/link-options.rst +1 -1
index edda1ca..4b3200a 100644
@@ -111,7 +111,7 @@
   Valid syntax:
   ::
 
-     local host|* [port] [protocol]
+     local host|* [port] [protocol] [bind device]
 
   Local host name or IP address and port for bind. If specified, OpenVPN will bind
   to this address. If unspecified, OpenVPN will bind to all interfaces.
doc/man-sections/vpn-network-options.rst +3 -1
index 33ebedb..3b30ed9 100644
@@ -6,8 +6,10 @@
 routing.
 
 --bind-dev device
-  (Linux only) Set ``device`` to bind the server socket to a
+  (Linux only) Set ``device`` to bind all the server sockets to a
   `Virtual Routing and Forwarding`_ device
+  This option can also be used inside a ``--local`` statement
+  allowing to bind a single socket to specific device.
 
 --block-ipv6
   On the client, instead of sending IPv6 packets over the VPN tunnel, all
src/openvpn/options.c +13 -1
index 70af6d2..e1c3b7d 100644
@@ -3830,6 +3830,7 @@
         ASSERT(e);
         e->port = o->ce.local_port;
         e->proto = o->ce.proto;
+        e->bind_dev = o->bind_dev;
     }
 
     /* use the same listen list for every outgoing connection */
@@ -5972,7 +5973,7 @@
         VERIFY_PERMISSION(OPT_P_UP);
         options->ifconfig_nowarn = true;
     }
-    else if (streq(p[0], "local") && p[1] && !p[4])
+    else if (streq(p[0], "local") && p[1] && !p[5])
     {
         struct local_entry *e;
 
@@ -5998,6 +5999,17 @@
         {
             e->proto = ascii2proto(p[3]);
         }
+#if defined(TARGET_LINUX)
+        if (p[4])
+        {
+            e->bind_dev = p[4];
+        }
+#else
+        if (p[4])
+        {
+            msg(M_WARN, "Note: bind_dev is ignored on non-Linux systems");
+        }
+#endif
     }
     else if (streq(p[0], "remote-random") && !p[1])
     {
src/openvpn/options.h +1 -0
index a111cf8..c9f61d1 100644
@@ -101,6 +101,7 @@
     const char *local;
     const char *port;
     int proto;
+    const char *bind_dev;
 };
 
 struct connection_entry
src/openvpn/socket.c +3 -1
index 624ce4f..018d12d 100644
@@ -1349,6 +1349,7 @@
     const char *host = o->ce.local_list->array[sock_index]->local;
     const char *port = o->ce.local_list->array[sock_index]->port;
     int proto = o->ce.local_list->array[sock_index]->proto;
+    const char *bind_dev = o->ce.local_list->array[sock_index]->bind_dev;
     const char *remote_host = o->ce.remote;
     const char *remote_port = o->ce.remote_port;
 
@@ -1409,7 +1410,8 @@
 #endif
 
     sock->mark = o->mark;
-    sock->bind_dev = o->bind_dev;
+    /* bind_dev from local_list will trump the global option */
+    sock->bind_dev = bind_dev ? bind_dev : o->bind_dev;
     sock->info.proto = proto;
     sock->info.af = o->ce.af;
     sock->info.remote_float = o->ce.remote_float;

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1625?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings?usp=email

Gerrit-MessageType: newpatchset
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I6319c951327a9b994ffae0ba35270b0887455203
Gerrit-Change-Number: 1625
Gerrit-PatchSet: 2
Gerrit-Owner: its_Giaan <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: its_Giaan <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>

#4 lore raw
In reply to a message not in the archive

Attention is currently required from: flichtenheld, plaisthos.

its_Giaan has posted comments on this change by its_Giaan. ( http://gerrit.openvpn.net/c/openvpn/+/1625?usp=email )

Change subject: Enable per-socket bind_dev via --local
......................................................................

Patch Set 2:

(4 comments)

File doc/man-sections/link-options.rst:

http://gerrit.openvpn.net/c/openvpn/+/1625/comment/deef9428_ebae9b5d?usp=email :
PS1, Line 114: local host|* [port] [protocol] [bind device]

Quoted 1 line

Should also add a reference to --bind-dev somewhere in the documentation below. […]

I did it only for --bind-dev at the moment, if you're fine with that will do the same way for --port and --proto in a different patch.

File src/openvpn/options.c:

http://gerrit.openvpn.net/c/openvpn/+/1625/comment/63bf8009_24bcad5f?usp=email :
PS1, Line 6010: msg(M_WARN | M_ERRNO, "Note: bind_dev is ignored on non-Linux systems");

Quoted 1 line

No syscalls involved here, so M_ERRNO makes no sense

Done

http://gerrit.openvpn.net/c/openvpn/+/1625/comment/d7b038f0_ac763769?usp=email :
PS1, Line 6541: #if defined(TARGET_LINUX)

Quoted 1 line

Why this random change?

Just a leftover, initially this patch also aimed to enable bind-dev for freebsd, then I decided to do that in a different patch.

File src/openvpn/socket.c:

http://gerrit.openvpn.net/c/openvpn/+/1625/comment/cf628b0d_3b3678c2?usp=email :
PS1, Line 1413: /* bind_dev from local_list will trump on the global option. */

Quoted 1 line

Remove "on", remove the trailing full stop

Done

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1625?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings?usp=email

Gerrit-MessageType: comment
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I6319c951327a9b994ffae0ba35270b0887455203
Gerrit-Change-Number: 1625
Gerrit-PatchSet: 2
Gerrit-Owner: its_Giaan <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Comment-Date: Mon, 13 Apr 2026 15:20:05 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Comment-In-Reply-To: flichtenheld <[email protected]...>

#5 lore raw
In reply to a message not in the archive

Attention is currently required from: its_Giaan, plaisthos.

flichtenheld has posted comments on this change by its_Giaan. ( http://gerrit.openvpn.net/c/openvpn/+/1625?usp=email )

Change subject: Enable per-socket bind_dev via --local
......................................................................

Patch Set 2: Code-Review-1

(2 comments)

Patchset:

PS2:
Please also update the usage section in options.c

File doc/man-sections/link-options.rst:

http://gerrit.openvpn.net/c/openvpn/+/1625/comment/e7ea6dc8_91ee5751?usp=email :
PS1, Line 114: local host|* [port] [protocol] [bind device]

Quoted 1 line

I did it only for --bind-dev at the moment, if you're fine with that will do the same way for --port […]

That mention under --bind-dev is okay, but I actually meant to add a pointer to --bind-dev here at --local 😊

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1625?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings?usp=email

Gerrit-MessageType: comment
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I6319c951327a9b994ffae0ba35270b0887455203
Gerrit-Change-Number: 1625
Gerrit-PatchSet: 2
Gerrit-Owner: its_Giaan <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: its_Giaan <[email protected]...>
Gerrit-Comment-Date: Tue, 14 Apr 2026 11:08:52 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: Yes
Comment-In-Reply-To: its_Giaan <[email protected]...>
Comment-In-Reply-To: flichtenheld <[email protected]...>

#6 lore raw
In reply to a message not in the archive

Attention is currently required from: flichtenheld, its_Giaan, plaisthos.

Hello flichtenheld, plaisthos,

I'd like you to reexamine a change. Please visit

    http://gerrit.openvpn.net/c/openvpn/+/1625?usp=email

to look at the new patch set (#3).

The following approvals got outdated and were removed:
Code-Review-1 by flichtenheld

Change subject: Enable per-socket bind_dev via --local
......................................................................

Enable per-socket bind_dev via --local

A bind device can now be specified within a
--local statement allowing to bind
different sockets to different devices.

While at it, improved the man-section for
--local.

Change-Id I6319c951327a9b994ffae0ba35270b0887455203

---
M doc/man-sections/link-options.rst
M doc/man-sections/vpn-network-options.rst
M src/openvpn/options.c
M src/openvpn/options.h
M src/openvpn/socket.c

5 files changed, 29 insertions(+), 5 deletions(-)

git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/25/1625/3

doc/man-sections/link-options.rst +6 -1
index edda1ca..0c4df71 100644
@@ -111,12 +111,17 @@
   Valid syntax:
   ::
 
-     local host|* [port] [protocol]
+     local host|* [port] [protocol] [bind device]
 
   Local host name or IP address and port for bind. If specified, OpenVPN will bind
   to this address. If unspecified, OpenVPN will bind to all interfaces.
   '*' can be used as hostname and means 'any host' (OpenVPN will listen on what
   is returned by the OS).
+
+  The optional arguments correspond to existing options: ``port`` to
+  ``--lport``, ``protocol`` to ``--proto``, and ``bind device`` to
+  ``--bind-dev``.
+
   On a client, or in point-to-point mode, this can only be specified once (1 socket).
 
   On an OpenVPN setup running as ``--server``, this can be specified multiple times
doc/man-sections/vpn-network-options.rst +3 -1
index 33ebedb..3b30ed9 100644
@@ -6,8 +6,10 @@
 routing.
 
 --bind-dev device
-  (Linux only) Set ``device`` to bind the server socket to a
+  (Linux only) Set ``device`` to bind all the server sockets to a
   `Virtual Routing and Forwarding`_ device
+  This option can also be used inside a ``--local`` statement
+  allowing to bind a single socket to specific device.
 
 --block-ipv6
   On the client, instead of sending IPv6 packets over the VPN tunnel, all
src/openvpn/options.c +16 -2
index 70af6d2..63db6db 100644
@@ -128,10 +128,12 @@
     "--version       : Show copyright and version information.\n"
     "\n"
     "Tunnel Options:\n"
-    "--local host|* [port]: Local host name or IP address and port for bind.\n"
+    "--local host|* [port] [protocol] [bind-dev]: Local host name or IP address and port for bind.\n"
     "                        If specified, OpenVPN will bindto this address. If unspecified,\n"
     "                        OpenVPN will bind to all interfaces. '*' can be used as hostname\n"
     "                        and means 'any host' (OpenVPN will listen on what is returned by the OS).\n"
+    "                        The optional arguments correspond to existing options: ``port`` to ``--lport``,\n"
+    "                        ``protocol`` to ``--proto``, and ``bind device`` to --bind-dev``.\n"
     "                        On a client, or in point-to-point mode, this can only be specified once (1 socket).\n"
     "                        On an OpenVPN setup running as ``--server``, this can be specified multiple times\n"
     "                        to open multiple listening sockets on different addresses and/or different ports.\n"
@@ -3830,6 +3832,7 @@
         ASSERT(e);
         e->port = o->ce.local_port;
         e->proto = o->ce.proto;
+        e->bind_dev = o->bind_dev;
     }
 
     /* use the same listen list for every outgoing connection */
@@ -5972,7 +5975,7 @@
         VERIFY_PERMISSION(OPT_P_UP);
         options->ifconfig_nowarn = true;
     }
-    else if (streq(p[0], "local") && p[1] && !p[4])
+    else if (streq(p[0], "local") && p[1] && !p[5])
     {
         struct local_entry *e;
 
@@ -5998,6 +6001,17 @@
         {
             e->proto = ascii2proto(p[3]);
         }
+#if defined(TARGET_LINUX)
+        if (p[4])
+        {
+            e->bind_dev = p[4];
+        }
+#else
+        if (p[4])
+        {
+            msg(M_WARN, "Note: bind_dev is ignored on non-Linux systems");
+        }
+#endif
     }
     else if (streq(p[0], "remote-random") && !p[1])
     {
src/openvpn/options.h +1 -0
index a111cf8..c9f61d1 100644
@@ -101,6 +101,7 @@
     const char *local;
     const char *port;
     int proto;
+    const char *bind_dev;
 };
 
 struct connection_entry
src/openvpn/socket.c +3 -1
index 624ce4f..018d12d 100644
@@ -1349,6 +1349,7 @@
     const char *host = o->ce.local_list->array[sock_index]->local;
     const char *port = o->ce.local_list->array[sock_index]->port;
     int proto = o->ce.local_list->array[sock_index]->proto;
+    const char *bind_dev = o->ce.local_list->array[sock_index]->bind_dev;
     const char *remote_host = o->ce.remote;
     const char *remote_port = o->ce.remote_port;
 
@@ -1409,7 +1410,8 @@
 #endif
 
     sock->mark = o->mark;
-    sock->bind_dev = o->bind_dev;
+    /* bind_dev from local_list will trump the global option */
+    sock->bind_dev = bind_dev ? bind_dev : o->bind_dev;
     sock->info.proto = proto;
     sock->info.af = o->ce.af;
     sock->info.remote_float = o->ce.remote_float;

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1625?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings?usp=email

Gerrit-MessageType: newpatchset
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I6319c951327a9b994ffae0ba35270b0887455203
Gerrit-Change-Number: 1625
Gerrit-PatchSet: 3
Gerrit-Owner: its_Giaan <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: its_Giaan <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>

#7 lore raw
In reply to a message not in the archive

Attention is currently required from: flichtenheld, plaisthos.

its_Giaan has posted comments on this change by its_Giaan. ( http://gerrit.openvpn.net/c/openvpn/+/1625?usp=email )

Change subject: Enable per-socket bind_dev via --local
......................................................................

Patch Set 3:

(2 comments)

Patchset:

PS2:

Quoted 1 line

Please also update the usage section in options. […]

Done

File doc/man-sections/link-options.rst:

http://gerrit.openvpn.net/c/openvpn/+/1625/comment/f9bbece1_e8584586?usp=email :
PS1, Line 114: local host|* [port] [protocol] [bind device]

Quoted 1 line

That mention under --bind-dev is okay, but I actually meant to add a pointer to --bind-dev here […]

Done

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1625?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings?usp=email

Gerrit-MessageType: comment
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I6319c951327a9b994ffae0ba35270b0887455203
Gerrit-Change-Number: 1625
Gerrit-PatchSet: 3
Gerrit-Owner: its_Giaan <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Comment-Date: Wed, 15 Apr 2026 15:33:01 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Comment-In-Reply-To: its_Giaan <[email protected]...>
Comment-In-Reply-To: flichtenheld <[email protected]...>

#8 lore raw
In reply to a message not in the archive

Attention is currently required from: its_Giaan, plaisthos.

flichtenheld has posted comments on this change by its_Giaan. ( http://gerrit.openvpn.net/c/openvpn/+/1625?usp=email )

Change subject: Enable per-socket bind_dev via --local
......................................................................

Patch Set 3: Code-Review-1

(2 comments)

File doc/man-sections/link-options.rst:

http://gerrit.openvpn.net/c/openvpn/+/1625/comment/ae0af796_9da7928a?usp=email :
PS3, Line 121: The optional arguments correspond to existing options: ``port`` to
Maybe better:

The optional arguments override defaults set by the following options:
* ``port`` overrides ``--lport``
* ``protocol`` overrides ``--proto``
* ``bind device`` overrides ``--bind-dev``

(To explicitly say that these options set defaults which we can then override)

File doc/man-sections/vpn-network-options.rst:

http://gerrit.openvpn.net/c/openvpn/+/1625/comment/182e6971_7f4b5f87?usp=email :
PS3, Line 11: This option can also be used inside a ``--local`` statement
Maybe better:

The default defined by this option can be overridden on a per-socket basis by specifying a ``bind device`` argument to ``--local``.

The current text sounds like you can use ``--bind-dev`` in a different context which is not correct.

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1625?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings?usp=email

Gerrit-MessageType: comment
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I6319c951327a9b994ffae0ba35270b0887455203
Gerrit-Change-Number: 1625
Gerrit-PatchSet: 3
Gerrit-Owner: its_Giaan <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: its_Giaan <[email protected]...>
Gerrit-Comment-Date: Wed, 15 Apr 2026 15:41:47 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: Yes

#9 lore raw
In reply to a message not in the archive

Attention is currently required from: flichtenheld, its_Giaan, plaisthos.

Hello flichtenheld, plaisthos,

I'd like you to reexamine a change. Please visit

    http://gerrit.openvpn.net/c/openvpn/+/1625?usp=email

to look at the new patch set (#4).

The following approvals got outdated and were removed:
Code-Review-1 by flichtenheld

Change subject: Enable per-socket bind_dev via --local
......................................................................

Enable per-socket bind_dev via --local

A bind device can now be specified within a
--local statement allowing to bind
different sockets to different devices.

While at it, improved the man-section for
--local.

Change-Id I6319c951327a9b994ffae0ba35270b0887455203

---
M doc/man-sections/link-options.rst
M doc/man-sections/vpn-network-options.rst
M src/openvpn/options.c
M src/openvpn/options.h
M src/openvpn/socket.c

5 files changed, 31 insertions(+), 5 deletions(-)

git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/25/1625/4

doc/man-sections/link-options.rst +8 -1
index edda1ca..1dcaba1 100644
@@ -111,12 +111,19 @@
   Valid syntax:
   ::
 
-     local host|* [port] [protocol]
+     local host|* [port] [protocol] [bind device]
 
   Local host name or IP address and port for bind. If specified, OpenVPN will bind
   to this address. If unspecified, OpenVPN will bind to all interfaces.
   '*' can be used as hostname and means 'any host' (OpenVPN will listen on what
   is returned by the OS).
+
+  Optional arguments override the corresponding default options:
+
+  - ``port`` overrides ``--lport``.
+  - ``protocol`` overrides ``--proto``.
+  - ``bind device`` overrides ``--bind-dev``.
+
   On a client, or in point-to-point mode, this can only be specified once (1 socket).
 
   On an OpenVPN setup running as ``--server``, this can be specified multiple times
doc/man-sections/vpn-network-options.rst +3 -1
index 33ebedb..f43382f 100644
@@ -6,8 +6,10 @@
 routing.
 
 --bind-dev device
-  (Linux only) Set ``device`` to bind the server socket to a
+  (Linux only) Set ``device`` to bind all the server sockets to a
   `Virtual Routing and Forwarding`_ device
+  The default set by this option can be overridden on a per-socket basis
+  by specifying a bind device argument via ``--local``.
 
 --block-ipv6
   On the client, instead of sending IPv6 packets over the VPN tunnel, all
src/openvpn/options.c +16 -2
index 70af6d2..63db6db 100644
@@ -128,10 +128,12 @@
     "--version       : Show copyright and version information.\n"
     "\n"
     "Tunnel Options:\n"
-    "--local host|* [port]: Local host name or IP address and port for bind.\n"
+    "--local host|* [port] [protocol] [bind-dev]: Local host name or IP address and port for bind.\n"
     "                        If specified, OpenVPN will bindto this address. If unspecified,\n"
     "                        OpenVPN will bind to all interfaces. '*' can be used as hostname\n"
     "                        and means 'any host' (OpenVPN will listen on what is returned by the OS).\n"
+    "                        The optional arguments correspond to existing options: ``port`` to ``--lport``,\n"
+    "                        ``protocol`` to ``--proto``, and ``bind device`` to --bind-dev``.\n"
     "                        On a client, or in point-to-point mode, this can only be specified once (1 socket).\n"
     "                        On an OpenVPN setup running as ``--server``, this can be specified multiple times\n"
     "                        to open multiple listening sockets on different addresses and/or different ports.\n"
@@ -3830,6 +3832,7 @@
         ASSERT(e);
         e->port = o->ce.local_port;
         e->proto = o->ce.proto;
+        e->bind_dev = o->bind_dev;
     }
 
     /* use the same listen list for every outgoing connection */
@@ -5972,7 +5975,7 @@
         VERIFY_PERMISSION(OPT_P_UP);
         options->ifconfig_nowarn = true;
     }
-    else if (streq(p[0], "local") && p[1] && !p[4])
+    else if (streq(p[0], "local") && p[1] && !p[5])
     {
         struct local_entry *e;
 
@@ -5998,6 +6001,17 @@
         {
             e->proto = ascii2proto(p[3]);
         }
+#if defined(TARGET_LINUX)
+        if (p[4])
+        {
+            e->bind_dev = p[4];
+        }
+#else
+        if (p[4])
+        {
+            msg(M_WARN, "Note: bind_dev is ignored on non-Linux systems");
+        }
+#endif
     }
     else if (streq(p[0], "remote-random") && !p[1])
     {
src/openvpn/options.h +1 -0
index a111cf8..c9f61d1 100644
@@ -101,6 +101,7 @@
     const char *local;
     const char *port;
     int proto;
+    const char *bind_dev;
 };
 
 struct connection_entry
src/openvpn/socket.c +3 -1
index 624ce4f..018d12d 100644
@@ -1349,6 +1349,7 @@
     const char *host = o->ce.local_list->array[sock_index]->local;
     const char *port = o->ce.local_list->array[sock_index]->port;
     int proto = o->ce.local_list->array[sock_index]->proto;
+    const char *bind_dev = o->ce.local_list->array[sock_index]->bind_dev;
     const char *remote_host = o->ce.remote;
     const char *remote_port = o->ce.remote_port;
 
@@ -1409,7 +1410,8 @@
 #endif
 
     sock->mark = o->mark;
-    sock->bind_dev = o->bind_dev;
+    /* bind_dev from local_list will trump the global option */
+    sock->bind_dev = bind_dev ? bind_dev : o->bind_dev;
     sock->info.proto = proto;
     sock->info.af = o->ce.af;
     sock->info.remote_float = o->ce.remote_float;

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1625?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings?usp=email

Gerrit-MessageType: newpatchset
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I6319c951327a9b994ffae0ba35270b0887455203
Gerrit-Change-Number: 1625
Gerrit-PatchSet: 4
Gerrit-Owner: its_Giaan <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: its_Giaan <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>

#10 lore raw
In reply to a message not in the archive

Attention is currently required from: flichtenheld, plaisthos.

its_Giaan has posted comments on this change by its_Giaan. ( http://gerrit.openvpn.net/c/openvpn/+/1625?usp=email )

Change subject: Enable per-socket bind_dev via --local
......................................................................

Patch Set 4:

(2 comments)

File doc/man-sections/link-options.rst:

http://gerrit.openvpn.net/c/openvpn/+/1625/comment/782b9dcc_8604ebab?usp=email :
PS3, Line 121: The optional arguments correspond to existing options: ``port`` to

Quoted 1 line

Maybe better: […]

Done

File doc/man-sections/vpn-network-options.rst:

http://gerrit.openvpn.net/c/openvpn/+/1625/comment/80bef053_6637ac96?usp=email :
PS3, Line 11: This option can also be used inside a ``--local`` statement

Quoted 1 line

Maybe better: […]

Well, what I meant was: "If you use this option, then all sockets will be bound to this specific device.". But I see your point.

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1625?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings?usp=email

Gerrit-MessageType: comment
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I6319c951327a9b994ffae0ba35270b0887455203
Gerrit-Change-Number: 1625
Gerrit-PatchSet: 4
Gerrit-Owner: its_Giaan <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Comment-Date: Wed, 15 Apr 2026 16:14:51 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Comment-In-Reply-To: flichtenheld <[email protected]...>